<?php
	
if ((isset($_SESSION['identifiant'])) AND (isset($_SESSION['groupe'])==2))
{
	if (isset($_POST['modifier'])) 
	{
		$req = $bdd->prepare('UPDATE groupes SET nom = :nom, fondateur = :fondateur, description = :description WHERE id=:id');
		$req->execute(array(
			'nom' => $_POST['nom'],
			'fondateur' => $_POST['fondateur'],
			'description' => $_POST['description'],
			'id' => $_POST['id']
		));
		header('Location: page.php?page=admin_clans'); 
	}
	elseif (isset($_POST['effacer'])) 
	{
		$req = $bdd->prepare('DELETE FROM admin_clans WHERE id=:id');
		$req->execute(array(
				'id' => $_POST['id']
		));
		header('Location: page.php?page=admin_clans'); 
	}
	elseif (isset($_POST['ajouter'])) 
	{
		$req = $bdd->prepare('INSERT INTO admin_clans (nom, fondateur, description) VALUES (:nom, :fondateur, :description)');
		$req->execute(array(
			'nom' => $_POST['nom'],
			'fondateur' => $_POST['fondateur'],
			'description' => $_POST['description']
		));
	}
	
	?>
	<h1 id="titre">Gestion des clans</h1>
	<table width="100%">
	<tr><th>Nom</th><th>Fondateur</th><th>Description</th></tr>
	<?php

	$req = $bdd->query('SELECT * FROM admin_clans');
	while ($donnees = $req->fetch())
	{
		?>
		<form method="post" action="page.php?page=admin_clans">
			<tr>
			<td><input type="text" name="nom" value="<?php echo $donnees['nom']; ?>" maxlength="250" size="10"></td>
			<td><input type="text" name="fondateur" value="<?php echo $donnees['fondateur']; ?>" maxlength="5" size="5"><input type="hidden" name="id" value="<?php echo $donnees['id']; ?>" /></td>
			<td><input type="text" name="description" value="<?php echo $donnees['description']; ?>" maxlength="250" size="25"></td>
			<td><input type="submit" value="Modifier" name="modifier" /><input type="submit" value="Effacer" name="effacer" /></td>
			</tr>
		</form>
		<?php
	}
	$req->closeCursor();
	?>
	<form method="post" action="page.php?page=admin_clans">
		<tr>
		<td><input type="text" name="nom" value="" maxlength="250" size="10"></td>
		<td><input type="text" name="fondateur" maxlength="5" size="5"></td>
		<td><input type="text" name="description" maxlength="250" size="25"></td>
		<td width="25%"><input type="submit" value="Ajouter un clan" name="ajouter" /></td>
		</tr>
	</form>
	</table>
<?php
}
else
{
	echo NON_ACCES_ADMIN;
}
?>